import Vue from 'vue'
import Vuex from 'vuex';
Vue.use(Vuex);

var user = {
  username: "",
  password: "",
  academy: "",
  power: [],
  isAdmin: false,
  isLogin: false
}

const state={   //要设置的全局访问的state对象
  user,
  dialog : {
    "id": ""
  }
  //要设置的初始属性值
};
const getters = {   //实时监听state值的变化(最新状态)
  getUser(state){
    return state.user
  }
};
const mutations = {
 setUser(state,user){
   state.user.username = user.username;
   state.user.password = user.password;
   state.user.academy = user.academy;
   state.user.isAdmin = user.isAdmin;
   state.user.power = user.power;
 }
};
const actions = {
 storeUser(context,user){   //同上注释，user为要变化的形参
     context.commit('setUser',user)
  }
};
const store = new Vuex.Store({
    state,
    getters,
    mutations,
    actions
});
export default store;



// //引入modules中对应的组件
// import  dialog  from './dialog';
// import  user  from './user';
// import  article  from './article';




// export default new vuex.Store({
//   modules:{
//     dialog: dialog,
//     article: article,
//     user: user
//   }
// })



//获取值的方法     this.$store.getters.getUser;
//设置值的方法    this.$store.dispatch('storeUser'，user)      //6要变化的实参